// JavaScript Document

/*opening up the database*/
var db;

function  openNotesDatabase()
{
	db=openDatabase("NotesTest6","1.0","HTML5 SQLlite Example",200000);
}

function createNoteTable()
{
	db.transaction(function(tx)
	{
	tx.executeSql("Create table webkitstickynotes(id REAL UNIQUE,note TEXT, Timestamp REAL)",[],function (result)
	{
		alert('Create Webkit Notes: '+result);
	})
		
	});
}

function createNote(id, note)
{
	rightnow=new Date().getTime();
        db.transaction(function(tx){tx.executeSql("insert into WebKitStickyNotes values (?,?,?) ", [id,note,rightnow]);});
}

function deleteNote(id)
{
	db.transaction(function(tx){
	tx.executeSql("delete from WebkitStickyNotes where id=? ",[id]);
	});
}

function showNotes()
{
	db.transaction(function(tx){
		tx.executeSql("SELECT id,note,timestamp FROM WebKitStickyNotes",[],function(tx,result){
			var notesnode=document.getElementById('notes');
			notesnode.innerHTML="";
			for (var i=0;i<result.rows.length;++i)
			{
				var row= result.rows.item(i);
				var notediv=document.createElement('div');
				notediv.innerHTML='id: ' + row['id'] + ',timesstamp: ' + row['timestamp'] + ',note: '+row['note'];
				notesnode.appendChild(notediv);
			}
			},function(tx,error)
			{
				alert('failed to retive notes from database -' + error.message);
				return;
			});
		});
}

/*
function showschema()
{
	db.transaction(function(tx) {
		tx.executeSql(Select * from sqlite_master",[], function(tx,result)
		{
			var schemanode= document.getElementById('schema');
			schemanode.innerHTML="";
			
		}
		)
	}
	
	)
}
*/
